<template>
  <div style="height: 100%; width: 100%; position: relative">
      <div class="pagetop" :style="{height: isqueryreport == '0' ? '100px' : '135px'}">
          <template>
              <div style="width: 100%">
                  <div style="float: left; width: 100%">
                      <table style="font-size: 12px" class="table1style">
                          <tr>
                              <td>报告单元</td>
                              <td>
                                  <rm-ddl-rptunit prgno="LIS320" v-model="txtrptunit" filterable :clearable="false" defaultflag="1" :appendtobody="true" visible-change:true width="200px;" @change="rptunitchange"></rm-ddl-rptunit>
                              </td>
                              <td>标本日期</td>
                              <td>
                                  <el-date-picker v-model="sampledatetime" type="date" placeholder="选择日期" style="width: 130px" value-format="yyyy-MM-dd"> </el-date-picker>
                              </td>
                              <td>输入模版</td>
                              <td align="left">
                                  <el-select v-model="inputmdl" filterable clearable @change="InitPageDate" style="width: 100%">
                                      <el-option v-for="(item, index) in inputMdlOptions" :key="index" :value="item.inputmdlid" :label="item.mdlname" @click.native="inputmdlspecimen(item)"></el-option>
                                  </el-select>
                              </td>
                              <td>{{ specimenname }}</td>
                              <td colspan="2">
                                  <el-checkbox true-label="1" false-label="0" v-model="isqueryreport" @change="searchreportchange">查询已有报告</el-checkbox>
                              </td>
                          </tr>
                          <tr>
                              <td style="font-weight: boleder; font-size: 16px">样本号</td>
                              <td colspan="3" class="samplenoclass">
                                  <div class="el-input el-input--small">
                                      <input v-model="sampleno" placeholder="可以输入如：1,2,5-8等格式,存盘后标本号自动递增" style="width: 100%" class="sampleno-input el-input__inner" @keydown.enter="inputConfirm()" ref="samplenoinput">
                                  </div>
                              </td>
                              <td v-if="diffresultinput == '1'">
                                  <el-button @click="inputConfirm()">确定</el-button>
                              </td>
                              <td colspan="2">
                                  <el-checkbox true-label="1" false-label="0" v-model="diffresultinput" @change="diffresultchange">开启差异结果模式</el-checkbox>
                              </td>
                              <td v-if="diffresultinput == '1'">归类方式</td>
                              <td v-if="diffresultinput == '1'">
                                  <el-select v-model="sortclass" filterable @change="sortclassChange" style="width: 100%">
                                      <el-option v-for="(item, index) in sortclassOption" :key="index" :value="item.value" :label="item.name"></el-option>
                                  </el-select>
                              </td>
                              <!-- <p>标本号可以输入如：1,2,5-8等格式</p>
                  <p>结果区域最后一行回车可直接新增</p>
                  <p>检验项目不输入直接回车能够存盘</p>
                  <p>存盘后标本号自动递增</p>
                  <p>存盘后检验结果自动清除</p> -->
                          </tr>
                          <tr v-if="isqueryreport == '1'">
                              <td>病人类型</td>
                              <td>
                                  <rm-ddl-common datatype="seccode" kindno="PT" dataname="病人类型" v-model="pattypecode" width="200px"></rm-ddl-common>
                              </td>
                              <td>审核状态</td>
                              <td>
                                  <el-select v-model="checkflag" filterable style="width: 130px">
                                      <el-option v-for="(item, index) in checkOptions" :key="index" :value="item.value" :label="item.name"></el-option>
                                  </el-select>
                              </td>
                              <td>样本号前缀</td>
                              <td align="left">
                                  <el-input v-model="samplenopre" placeholder="请输入样本号前缀" style="width: 100%"></el-input>
                              </td>
                          </tr>
                      </table>
                  </div>
                  <div style="float: left; width: 100%">
                      <table style="float: right">
                          <tr>
                              <td v-if="isqueryreport == '1'">
                                  <el-button type="primary" @click="searchreport()">查询</el-button>
                              </td>
                              <td>
                                  <el-button icon="el-icon-document" @click="saverecord()">保存</el-button>
                              </td>
                              <td>
                                  <el-button icon="el-icon-plus" @click="operatedata(1)" v-has="'PADD'">新增</el-button>
                              </td>
                              <td v-if="diffresultinput == '1'">
                                  <el-button icon="el-icon-delete" @click="operatedata(3)" v-has="'PDELETE'">全部删除</el-button>
                              </td>
                              <td>
                                  <el-button icon="el-icon-delete" @click="operatedata(2)" v-has="'PDELETE'">删除</el-button>
                              </td>
                              <td>
                                  <el-button icon="el-icon-full-screen" @click="barcodeScan()">条码扫描输入</el-button>
                              </td>
                          </tr>
                      </table>
                  </div>
              </div>
          </template>
      </div>
      <div class="pagecenter" :style="{top: isqueryreport == '0' ? '105px' : '140px'}">
          <rm-layout-left :splitwidth=5 :fixsize=670>
              <template v-slot:fix>
                  <vxe-table :loading="loading" :data.sync="tableData" border fit :mouse-config="{ selected: true }" :edit-config="{ trigger: 'click', mode: 'cell', showStatus: true, showIcon: false, activeMethod: activeCell }" height="auto" header-align="center" highlight-current-row highlight-hover-row ref="xTable" resizable show-header-overflow="tooltip" show-overflow="tooltip" size="mini" stripe :cell-class-name="cellClassName" @current-change="currentChangeEvent" @cell-dblclick="opendialog">
                      <vxe-table-column type="index" title="NO." width="50" align="center"></vxe-table-column>
                      <vxe-table-column v-if="diffresultinput == '1'" field="sampleno" title="样本号" width="100" align="center"></vxe-table-column>
                      <vxe-table-column field="rpt_itemname" title="报告项目" width="300" :edit-render="{ name: 'input', autoselect: true }">
                          <template v-slot:edit="{ row }">
                              <el-input v-model="row.rpt_itemname" @change="RptChange(row)"></el-input>
                          </template>
                      </vxe-table-column>
                      <vxe-table-column field="result_str" title="检验结果" width="200" :edit-render="{ name: 'input', autoselect: true }">
                          <template v-slot:edit="{ row, column, rowIndex }">
                              <el-input v-model="row.result_str" @keyup.down.native="inputMove(1, column, rowIndex)" @keyup.up.native="inputMove(0, column, rowIndex)" @keyup.enter.native="enterMethod(column, rowIndex)"></el-input>
                          </template>
                      </vxe-table-column>
                  </vxe-table>
              </template>
              <div style="height:100%;width:100%;">
                  <div v-if="isqueryreport == '0'" style="width: 100%; float: left; height: 100%; border: 1px solid #ccc; overflow: auto" id="showbox">
                      <div v-for="(item, index) in msgList" v-html="item" :key="index"></div>
                  </div>
                  <div v-else style="width: 100%; height: 100%;">
                      <vxe-table :loading="reportloading" :data.sync="reportTableData" border fit  height="auto" header-align="center" highlight-current-row highlight-hover-row ref="xReportTable" resizable show-header-overflow="tooltip" show-overflow="tooltip" size="mini" stripe>
                          <vxe-table-column type="selection" width="30" align="center"></vxe-table-column>
                          <vxe-table-column field="cp_result" title="处理结果" width="150"></vxe-table-column>
                          <vxe-table-column field="rechkflag" title="审" width="30" align="center">
                              <template v-slot="{ row }">
                                  <div v-if="row.rechkflag == '9'"><span v-bind:style="{ color: 'black' }">审</span></div>
                                  <div v-else-if="row.rechkflag == '1'"><span v-bind:style="{ color: 'black' }">签</span></div>
                                  <div v-else-if="row.prechkflag == '1'"><span v-bind:style="{ color: 'black' }">待</span></div>
                                  <div v-else-if="row.prechkflag != '1' && row.prechkflag != '0'">{{ row.prechkflag }}</div>
                              </template>
                          </vxe-table-column>
                          <vxe-table-column field="sampleno" title="样本号" width="100" align="center"></vxe-table-column>
                          <vxe-table-column field="reportid" title="报告ID" width="150"></vxe-table-column>
                          <vxe-table-column field="pat_name" title="姓名" width="100"></vxe-table-column>
                          <vxe-table-column field="pat_no" title="病人号" width="100"></vxe-table-column>
                          <vxe-table-column field="pat_typecodename" title="病人类型" width="100"></vxe-table-column>
                          <vxe-table-column field="pat_sexname" title="性别" width="100"></vxe-table-column>
                          <vxe-table-column field="pat_agestr" title="年龄" width="100"></vxe-table-column>
                          <vxe-table-column field="barcode" title="条码号" width="100"></vxe-table-column>
                          <vxe-table-column field="req_reason" title="送检目的" width="100"></vxe-table-column>
                      </vxe-table>
                  </div>
              </div>
          </rm-layout-left>
      </div>

      <el-dialog width="1000px" top="10px" :append-to-body="true" :close-on-click-modal="false" title="选择报告项目" :visible.sync="outerVisible" :destroy-on-close="true">
          <rm-pop-rptitem prgno="LIS320" @cancel="outerVisible = false" :isAllRpt="1" @selitem="addrptitem" :rptunitid="txtrptunit"></rm-pop-rptitem>
      </el-dialog>

      <el-dialog width="1000px" top="10px" :append-to-body="true" :close-on-click-modal="false" title="项目文字结果" :visible.sync="outerVisible2">
          <rm_ItemTxtResult @change="itemtxtresChage" :rpt_itemcode="txtrpt_itemcode" resultkind="0" @cancel="outerVisible2 = false" ref="txtresult"></rm_ItemTxtResult>
      </el-dialog>
  </div>
</template>

<script type="text/javascript">
import XE from "xe-utils";
export default {
  name: "LIS320",
  data() {
      return {
          loading: false,
          outerVisible: false,
          outerVisible2: false,
          txtrptunit: "",
          sampleno: "",
          samplenocopy: 0,
          inputmdl: "",
          sampledatetime: "",
          inputMdlOptions: [],
          tableData: [],
          specimenname: "",
          tempindex: 0,
          selectrow: "",
          txtrpt_itemcode: "",
          okFirstLoading: true,
          msgList: [],
          snos: [],
          ddlData: [],
          isqueryreport: "0",
          reportloading: false,
          reportTableData: [],
          checkOptions: [
              {value: "all",name:"全部"},
              {value: "0",name:"未审核"},
              {value: "3",name:"待审核"},
          ],
          pattypecode: "",
          checkflag: "all",
          samplenopre: "",
          diffresultinput: "0",
          initrptitemlist: [],
          initsamplelist: [],
          initrptitemflag: false,
          sortclass: "1",
          sortclassOption: [
              {value: "1",name:"按报告项目归类"},
              {value: "2",name:"按样本号归类"},
          ],
          enterlockflag: false,//回车事件锁，防止回车太快导致连续保存
      };
  },
  created() {
      var isqueryreport = localStorage.getItem("LIS320_SEARCH_REPORT");
      if(isqueryreport){
          this.isqueryreport = isqueryreport;
      }
      var diffresultinput = localStorage.getItem("LIS320_DIFF_RESULT");
      if(diffresultinput){
          this.diffresultinput = diffresultinput;
      }
      var sortclass = localStorage.getItem("LIS320_SORT_CLASS");
      if(sortclass){
          this.sortclass = sortclass;
      }
      this.InitPageDate(); //初始化主列表
      this.InitDate();
  },
  mounted() {},
  updated() {
      if (this.okFirstLoading) {
          let currentrow = this.$refs.xTable.getData(0);
          this.$nextTick(() => {
              if (currentrow) {
                  this.okFirstLoading = false;
                  this.$refs.xTable.setCurrentRow(currentrow);
              }
          });
      }
  },
  methods: {
      searchreportchange(val) {
          localStorage.setItem("LIS320_SEARCH_REPORT", val);
      },
      diffresultchange(val) {
          this.tableData = [];
          localStorage.setItem("LIS320_DIFF_RESULT", val);
          if(val == "1") {
              this.$alert("开启差异结果模式后，当输入一个样本号的最后一个项目结果时，将进行自动保存，无需手动保存！", "提示");
          }
      },
      sortclassChange(val) {
          localStorage.setItem("LIS320_SORT_CLASS", val);
          this.tableData = [];
          this.generateData(this.initsamplelist, this.initrptitemlist);
      },
      inputConfirm() {
          let data = [];
          let curdata = this.$refs.xTable.getTableData().fullData;
          console.log(curdata);
          console.log(this.tableData);
          this.tableData.forEach((item) => {
              if(item.rpt_itemcode && item.rpt_itemname) {
                  data.push(item);
              }
          });
          //未分配样本号的记录为初始记录
          if (!data.find(item => item.sampleno)) {
              this.initrptitemlist = XE.clone(data, true);
              this.initrptitemflag = true;
          }
          if(data.length > 0) {
              if(this.sampleno) {
                  this.$tool
                      .request({
                          url: "LIS/LIS3/LIS320",
                          method: "post",
                          data: {
                              action: "getsampleno",
                              sampleno: this.sampleno,
                          },
                      })
                      .then((res) => {
                          if (res.hasOwnProperty("flag") && res.flag == "-1") {
                              this.$alert(res.msg, "提示");
                          } else {
                              this.snos = res.nos;
                              if (this.snos && this.snos.length > 0) {
                                  //第一次分配
                                  if (this.initrptitemflag) {
                                      this.tableData = [];
                                      this.initsamplelist = XE.clone(this.snos, true);
                                  } else {
                                      this.initsamplelist.push(...this.snos);
                                  }
                                  this.generateData(this.snos, this.initrptitemlist).then(()=>{
                                      this.initrptitemflag = false;
                                      this.sampleno = res.nextno;
                                  });
                              } else {
                                  this.msgList.push("分配样本号失败!");
                              }
                          }
                      })
                      .catch((e) => {
                          this.msgList.push("分配样本号异常!");
                      });
              } else {
                  this.$alert("请输入样本号！").then(()=>{
                      this.$refs.samplenoinput.focus();
                  });
              }
          } else {
              this.$alert("请先添加一个报告项目后再点击确定");
          }
      },
      generateData(samplenolist, rptitemlist) {
          return new Promise((s, f) => {
              let scrollrow = {};
              if (samplenolist && samplenolist.length > 0) {
                  if(this.sortclass == "1") {
                      rptitemlist.forEach((item, index1)=>{
                          samplenolist.forEach((item2, index2)=>{
                              let rowdata = {
                                  sampleno: item2,
                                  rpt_itemcode: item.rpt_itemcode,
                                  rpt_itemname: item.rpt_itemname,
                                  result_str: item.result_str,
                                  flag: "1",
                              };
                              if(index1 == 0 && index2 == 0) scrollrow = rowdata;
                              this.tableData.push(rowdata);
                          });
                      });
                  } else {
                      samplenolist.forEach((item, index1)=>{
                          rptitemlist.forEach((item2, index2)=>{
                              let rowdata = {
                                  sampleno: item,
                                  rpt_itemcode: item2.rpt_itemcode,
                                  rpt_itemname: item2.rpt_itemname,
                                  result_str: item2.result_str,
                                  flag: "1",
                              };
                              if(index1 == 0 && index2 == 0) scrollrow = rowdata;
                              this.tableData.push(rowdata);
                          });
                      });
                  }
              } else {
                  this.tableData = rptitemlist;
              }
              

              if (this.tableData.length > 0) {
                  let selectrow = {};
                  if(this.initrptitemflag) {
                      selectrow = this.tableData[0];
                  } else {
                      selectrow = scrollrow;
                  }
                  this.$refs.xTable.setCurrentRow(selectrow).then(() => {
                      this.$refs.xTable.setActiveCell(selectrow, "result_str");
                  });
                  this.$refs.xTable.scrollToRow(selectrow).then(() => {
                      s();
                  });
              }
          });

      },
      enterMethod(column, rowIndex) {
          try {
              let thisrow = this.$refs.xTable.getCurrentRow();
              // let thisrow = this.$refs.xTable.tableData[rowIndex - 1];
              this.$tool
                  .request({
                      url: "ucent/ddl",
                      method: "post",
                      data: {
                          action: "ItemTxtResult",
                          rpt_itemcode: thisrow.rpt_itemcode,
                          resultkind: "0",
                      },
                  })
                  .then((res) => {
                      var rdata = res.Data;
                      let tresult = rdata.filter((item) => item.inputcode == thisrow.result_str);
                      if (tresult != null && tresult.length > 0 && tresult[0].textvalue != "") {
                          thisrow.result_str = tresult[0].textvalue;
                      }
                      //开启了差异结果模式后使用自动保存
                      if(this.diffresultinput == "1") {
                          //如果当前行是该样本号的最后一行，自动保存
                          let belowRows = this.$refs.xTable.tableFullData.slice(rowIndex + 1);
                          let belowrow = belowRows.filter((item) => item.sampleno == thisrow.sampleno);
                          if (belowRows.length == 0 || belowrow.length == 0)
                          {
                              if(!this.enterlockflag) {
                                  this.enterlockflag = true;
                                  console.log("保存");
                                  this.singlesave(thisrow.sampleno)
                                      .then(()=>{
                                          this.inputMove(1, column, rowIndex);
                                          this.enterlockflag = false;
                                      }).catch(()=>{
                                          this.enterlockflag = false;
                                      });
                              }
                          } else {
                              this.inputMove(1, column, rowIndex);
                          }
                      } else {
                          this.inputMove(1, column, rowIndex);
                      }
                  })
                  .catch((e) => {
                      this.loading = false;
                  });
          } catch (e) {
              console.log("error", e);
          }
          //console.log("11", row.rpt_itemname);
      },
      inputMove(type, column, rowIndex) {
          if (type == 1) {//下一个
              let row = this.$refs.xTable.tableFullData[rowIndex + 1];
              if (row) {
                  this.$refs.xTable.setCurrentRow(row);
                  this.$refs.xTable.setActiveCell(row, column.property);
              }
          } else {//上一个
              let row = this.$refs.xTable.tableFullData[rowIndex - 1];
              if (row) {
                  this.$refs.xTable.setCurrentRow(row);
                  this.$refs.xTable.setActiveCell(row, column.property);
              }
          }
      },
      inputmdlspecimen(list) {
          this.specimenname = list.specimen_name;
      },
      // handlerrptitemchange(val) {
      //     this.txtrptunit = val;
      //     this.tableData = [];
      //     this.getinitdata(); //初始化下拉框的数据
      // },
      InitPageDate() {
          this.loading = true;
          this.$tool
              .request({
                  url: "LIS/LIS3/LIS320",
                  method: "post",
                  data: {
                      action: "InitPageDate",
                      inputmdlid: this.inputmdl,
                  },
              })
              .then((res) => {
                  this.tableData = res.Data;
                  this.loading = false;
                  this.initrptitemflag = true;
                  this.initsamplelist = [];
                  this.initrptitemlist = XE.clone(this.tableData, true);
                  this.okFirstLoading = true;
              })
              .catch((e) => {
                  this.loading = false;
              });
      },
      InitDate() {
          var myDate = new Date(); //获取当前年份(2位)
          var year = myDate.getFullYear(); //获取完整的年份(4位,1970-????)
          var month = myDate.getMonth(); //获取当前月份(0-11,0代表1月)
          var day = myDate.getDate(); //获取当前日(1-31)
          var dayNow = year + "-" + (month + 1) + "-" + day;
          this.sampledatetime = dayNow;
      },
      operatedata(index) {
          if (index == "1") {
              //新增
              this.$refs.xTable
                  .insert({
                      rpt_itemname: "",
                      result_str: "",
                      flag: "0",
                  })
                  .then(({ row }) => {
                      this.$refs.xTable.setCurrentRow(row);
                      this.$refs.xTable.setActiveRow(row, "rpt_itemname");
                      this.tableData = this.$refs.xTable.getTableData().fullData;
                  });
          } else if (index == "3") {
              this.tableData = [];
          } else {
              //删除
              var delrow = this.$refs.xTable.getCurrentRow();
              if (delrow) {
                  var alld = this.$refs.xTable.tableData;
                  var rowindex = alld.indexOf(delrow);
                  this.$refs.xTable.remove(delrow);
                  let havedata = this.$refs.xTable.tableData;
                  if (havedata.length > 0) {
                      if (rowindex >= havedata.length) rowindex = havedata.length - 1;
                      let selectrow = havedata[rowindex];
                      this.$refs.xTable.setCurrentRow(selectrow);
                      this.tableData = this.$refs.xTable.getTableData().fullData;
                  }
              }
          }
      },
      itemtxtresChage(val) {
          this.selectrow.result_str = val;
          this.outerVisible2 = false;
      },
      searchreport() {
          this.reportloading = true;
          this.$tool
              .request({
                  url: "LIS/LIS3/LIS320",
                  method: "post",
                  data: {
                      action: "queryreport",
                      pattypecode: this.pattypecode,
                      checkflag: this.checkflag,
                      samplenopre: this.samplenopre,
                      rptunitid: this.txtrptunit,
                      sampledatetime: this.sampledatetime,
                  },
              })
              .then((res) => {
                  this.reportTableData = res.dt;
                  this.reportloading = false;
                  this.snos = [];
              })
              .catch((e) => {

              });
      },
      saverecord() {
          //分两种模式，查询已有报告的情况下只修改已有报告，不勾的话就会插入新报告
          if (this.isqueryreport == "1") {
              let rows = this.$refs.xReportTable.getSelectRecords();
              if(rows && rows.length > 0){
                  this.snos = [];
                  for (let index = 0; index < rows.length; index++) {
                      const element = rows[index];
                      this.snos.push(element.sampleno);
                  }
                  if (this.snos && this.snos.length > 0) {
                      this.execsave(0);
                  }
              } else {
                  this.$alert("请选择报告保存！");
              }
          } else if (this.diffresultinput == "1") {
              if(this.initsamplelist && this.initsamplelist.length > 0) {
                  this.execsave(0);
              }
          }
          else {
              if (this.sampleno == "") {
                  this.sampleno = "1";
              }
              this.$tool
                  .request({
                      url: "LIS/LIS3/LIS320",
                      method: "post",
                      data: {
                          action: "getsampleno",
                          sampleno: this.sampleno,
                      },
                  })
                  .then((res) => {
                      if (res.hasOwnProperty("flag") && res.flag == "-1") {
                          this.$alert(res.msg, "提示");
                      } else {
                          this.snos = res.nos;
                          if (this.snos && this.snos.length > 0) {
                              this.execsave(0);
                          }
                          this.sampleno = res.nextno;
                      }
                  })
                  .catch((e) => {
                      //console.log("error", e);
                      this.msgList.push("存盘失败，检查样本号异常!");
                  });
          }
      },
      //单个保存，不进行循环保存
      singlesave(sampleno) {
          return new Promise((s, f) => {
              let itemdata = this.$refs.xTable.tableFullData.filter((item)=> item.sampleno == sampleno);
              this.$tool
                  .request({
                      url: "LIS/LIS3/LIS320",
                      method: "post",
                      data: {
                          action: "saverecord",
                          inputmdlid: this.inputmdl,
                          rptunitid: this.txtrptunit,
                          sampledatetime: this.sampledatetime,
                          sampleno: sampleno,
                          itemstr: itemdata,
                      },
                  })
                  .then((res) => {
                      if (this.isqueryreport == "1") {
                          console.log(sampleno);
                          var findrow = this.reportTableData.find((item) => item.sampleno == sampleno);
                          if(findrow) findrow.cp_result = "加入成功！";
                      } else {
                          this.msgList.push(res.retMsg);
                      }
                      s();
                  })
                  .catch((e) => {
                      if (this.isqueryreport == "1") {
                          var findrow = this.reportTableData.find((item) => item.sampleno == sampleno);
                          if(findrow) findrow.cp_result = "加入失败，发生异常";
                      } else {
                          this.msgList.push(sno + " 加入失败，发生异常");
                      }
                      f();
                  });
          });
          
      },
      execsave(index) {
          let samplelist = [];
          if (this.diffresultinput == "1") {
              samplelist = this.initsamplelist;
          } else {
              samplelist = this.snos;
          }
          if (index < samplelist.length) {
              let sno = samplelist[index];
              let itemdata = [];
              if(this.diffresultinput == "1") {
                  itemdata = this.$refs.xTable.tableFullData.filter((item)=> item.sampleno == sno);
              } else {
                  itemdata = this.$refs.xTable.tableFullData;
              }
              this.$tool
                  .request({
                      url: "LIS/LIS3/LIS320",
                      method: "post",
                      data: {
                          action: "saverecord",
                          inputmdlid: this.inputmdl,
                          rptunitid: this.txtrptunit,
                          sampledatetime: this.sampledatetime,
                          sampleno: sno,
                          itemstr: itemdata,
                      },
                  })
                  .then((res) => {
                      if (this.isqueryreport == "1") {
                          console.log(sno);
                          var findrow = this.reportTableData.find((item) => item.sampleno == sno);
                          if(findrow) findrow.cp_result = "加入成功！";
                      } else {
                          this.msgList.push(res.retMsg);
                      }
                      this.execsave(index + 1);
                  })
                  .catch((e) => {
                      if (this.isqueryreport == "1") {
                          var findrow = this.reportTableData.find((item) => item.sampleno == sno);
                          if(findrow) findrow.cp_result = "加入失败，发生异常";
                      } else {
                          this.msgList.push(sno + " 加入失败，发生异常");
                      }
                      this.execsave(index + 1);
                  });
          }
      },
      barcodeScan() {
          this.$prompt("请扫描条码", "提示", {
              confirmButtonText: "确定",
              cancelButtonText: "取消",
              cancelButtonClass: "el-button el-button--default el-button--small el-button--primary",
              confirmButtonClass: "el-button el-button--default el-button--small",
              focusCancelButton: false,
              closeOnClickModal: false,
              inputPattern: /^[0-9a-zA-Z_]{1,}$/,
              inputErrorMessage: "请输入条码!",
          })
              .then(({ value }) => {
                  if (value) {
                      this.getbarcodeScanResult(value);
                  } else {
                      this.$message({
                          type: "warning",
                          message: "无效的条码！",
                      });
                  }
              })
              .catch(() => {
                  this.$message({
                      type: "info",
                      message: "取消输入",
                  });
              });
      },
      getbarcodeScanResult(barcode) {
          this.$tool
              .request({
                  url: "LIS/LIS3/LIS320",
                  method: "post",
                  data: {
                      action: "getbarcodeScanResult",
                      rptunitid: this.txtrptunit,
                      sampledatetime: this.sampledatetime,
                      barcode: barcode,
                  },
              })
              .then((res) => {
                  if (res != -1) {
                      let result = res.dt;
                      result.forEach((item) => {
                          this.$refs.xTable.insert(item);
                      });
                  } else {
                      this.$message({
                          type: "warning",
                          message: "条码无效或对应的标本已经审核！",
                      });
                  }
              })
              .catch((e) => {
                  console.log("error", e);
              });
      },
      getinitdata() {
          this.$tool
              .request({
                  url: "LIS/LIS3/LIS320",
                  method: "post",
                  data: {
                      action: "getinitdata",
                      rptunitid: this.txtrptunit,
                  },
              })
              .then((response) => {
                  this.inputMdlOptions = response.inputMdlData;
              })
              .catch((e) => {
                  console.log("error", e);
              });
      },
      currentChangeEvent({ row, rowIndex }) {
          this.tempindex = rowIndex;
      },
      cellClassName({ columnIndex, row }) {
          if (columnIndex == "0" || columnIndex == "1") {
              if (row.flag == "1") {
                  //不能再次选择
                  return "col-orange";
              } else {
                  //新增的数据
                  return "";
              }
          } else {
              return "";
          }
      },
      activeCell({ row, columnIndex }) {
          if (this.diffresultinput == "1") {
              if (columnIndex == "1" || columnIndex == "2") {
                  if (row.flag == "0") {
                      return true;
                  } else {
                      return false;
                  }
              } else {
                  return true;
              }
          } else {
              if (columnIndex == "1") {
                  if (row.flag == "0") {
                      return true;
                  } else {
                      return false;
                  }
              } else {
                  return true;
              }
          }
      },
      opendialog({ row, column }) {
          if (column.property == "rpt_itemname") {
              if (row.flag == "0") {
                  this.outerVisible = true;
                  this.selectrow = row;
              }
          } else if (column.property == "result_str") {
              this.txtrpt_itemcode = row.rpt_itemcode;
              this.outerVisible2 = true;
              setTimeout(() => {
                  this.$refs.txtresult.InitPageDate();
              }, 1);
              this.selectrow = row;
              // if (row.flag == "0") {
              //
              //     this.outerVisible2 = true;
              //     setTimeout(() => {
              //         this.$refs.txtresult.InitPageDate();
              //     }, 1);

              //     this.selectrow = row;
              // } else {
              //     if (row.result_str == "") {
              //         this.txtrpt_itemcode = row.rpt_itemcode;
              //         this.outerVisible2 = true;

              //
              //     }
              // }
          }
      },
      async rptitemInput(row) {
          if (!this.ddlData.length) {
              this.ddlData = await this.$ddldata.getrptunititem(this.txtrptunit);
          }
          var select = this.ddlData.filter((item) => item.rpt_itemcode.toUpperCase() == row.rpt_itemname.toUpperCase() || item.itemcode_en.toUpperCase() == row.rpt_itemname.toUpperCase() || item.rpt_itemname.toUpperCase() == row.rpt_itemname.toUpperCase() || item.inputcode.toUpperCase() == row.rpt_itemname.toUpperCase());
          if (select && select.length > 0) {
              this.selectrow = row;
              this.addrptitem(select[0].rpt_itemcode, select[0].rpt_itemname, select[0]);
          } else {
              row.rpt_itemname = "";
          }
      },
      addrptitem(c, n, row) {
          this.outerVisible = false;
          let ishave = false;
          let datarecord = this.$refs.xTable.tableData;
          try {
              datarecord.forEach((item) => {
                  if (item.rpt_itemcode == c) {
                      ishave = true;
                      throw Error();
                  } else {
                      ishave = false;
                  }
              });
          } catch (e) {}
          if (ishave) {
              this.$message.error("所选数据重复，请重新选择！");
              return false;
          }
          this.selectrow.rpt_itemcode = c;
          this.selectrow.rpt_itemname = n;
          this.selectrow.flag = "1"; //标志位，新增后是否可修改
      },
      rptunitchange(val) {
          this.ddlData = this.$ddldata.getrptunititem(val);
      },
      RptChange(row) {
          this.rptitemInput(row);
      },
  },
  watch: {
      txtrptunit(val) {
          if (val) {
              this.tableData = [];
              this.getinitdata(); //初始化下拉框的数据
          }
      },
  },
};
</script>

<style scoped>
.pagetop {
  width: 100%;
  display: -webkit-box;
  -webkit-box-pack: left;
  -webkit-box-align: center;
  border: 1px solid #ccc;
  position: absolute;
  z-index: 99;
}

.pagecenter {
  position: absolute;
  width: 100%;
  left: 0;
  bottom: 0px;
  overflow: auto;
}

.middle-center {
  position: absolute;
  height: 100%;
  left: 0px;
  right: 505px;
  overflow: auto;
}

.middle-center-table {
  position: absolute;
  height: 100%;
  left: 0px;
  width:550px;
  overflow: auto;
}

.middle-right {
  position: absolute;
  height: 100%;
  width: 500px;
  right: 0px;
}

.middle-right-table {
  position: absolute;
  height: 100%;
  left: 555px;
  right: 0px;
}
.table1style tr td {
  padding: 0px 2px 0px 5px;
}
/deep/ .vxe-table .vxe-body--column.col-orange {
  background-color: #f8f8f8;
}
.samplenoclass .el-input--small .el-input__inner {
  /*     font-weight: 800;
      font-size: 18px;*/
}

.sampleno-input::-webkit-input-placeholder {
  color:blue;
}
</style>